package lk.week02;

import commons.ListNode;

/**
 * ClassName: P0203_RemoveNodeList
 * Description:
 * Author: xyf
 * Date: 5/20/23 10:50 PM
 * Version: 1.0
 **/
public class P0203_RemoveNodeList
{
    public ListNode removeElements(ListNode head, int val)
    {
        if (head == null)
        {
            return null;
        }
        ListNode dummy = new ListNode();
        dummy.next = head;
        ListNode cur = dummy;

        while (cur.next != null)
        {
            if (cur.next.val == val)
            {
                cur.next = cur.next.next;
            }
            else
            {
                cur = cur.next;
            }
        }

        return dummy.next;
    }
}
